var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');

var indexRouter = require('./routes/index');
var onlineRouter = require('./routes/online');
var infoRouter=require('./routes/courseinfo')
var usersRouter = require('./routes/users');
let centerRouter=require('./routes/usercenter')
let cors=require('cors')
var app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use(cookieParser());

app.use('/public', express.static(path.join(__dirname, 'public')));
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));

app.use('/api', indexRouter);
app.use('/api', onlineRouter);
app.use('/api', usersRouter);
app.use('/api', infoRouter);
app.use('/api', centerRouter);



// catch 404 and forward to error handler
app.use(function(req, res, next) {
  res.send({code: 404, msg:'404，走丢了'})
});

// error handler
app.use(function(err, req, res, next) {
  res.send(err)
});

module.exports = app;
